package com.interagriculture.controller;

import com.interagriculture.annotation.AdminVerify;
import com.interagriculture.common.Result;
import com.interagriculture.entity.Carousel;
import com.interagriculture.mapper.CarouselMapper;
import com.interagriculture.service.CarouselService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制轮播图的controller
 */
@RestController
@RequestMapping("/carousel")
@Slf4j
public class CarouselController {

    @Autowired
    private CarouselService carouselService;

    /**
     * 获取轮播图
     */
    @PostMapping("/get")
    public Result<List<Carousel>> getImage(@RequestBody(required = false) Carousel carousel){
        log.info("获取轮播图:{}",carousel);
        List<Carousel> list =  carouselService.getImage(carousel);
        return Result.ok(list);
    }

    /**
     * 修改轮播图
     */
    @AdminVerify
    @PostMapping("/update")
    public Result updateImage(@RequestBody(required = false) Carousel carousel){
        log.info("修改轮播图,id:{}",carousel);
        carouselService.updateImage(carousel);
        return Result.ok();
    }

}
